{	Problem: http://codeforces.ru/problemset/problem/106/C
	Verdict: Accepted
}
uses
    SysUtils, Math;

type
    al = array[0..20, 1..4] of longint;

var
    i, n, m, cx, dx, j, tt, ii, ans : longint;
    a : al;
    r : array[-1010..1010] of int64;
    ct : array[-1010..1010] of al;
    cur, jj, kk : int64;
        
begin 
    read(n, m, cx, dx);
    fillchar(r, sizeof(r), 0);
    r[0] := 0;
    for i := 1 to m do 
        read(a[i][1], a[i][2], a[i][3], a[i][4]);
    for i := -1010 to 0 do
        ct[i] := a;
    for i := 1 to n do begin
        cur := 0;
        tt := 0;
        ii := 0;
        for j := 1 to m do begin 
            jj := i - a[j][3];
            if (ct[jj][j][1] < ct[jj][j][2]) or (jj < 0) then 
                continue;
            kk := r[jj] + a[j][4];
            if cur < kk then begin
                tt := j;
                cur := kk;
                ii := jj;
            end;
        end;
        if cx <= i then begin
            jj := i - cx;
            kk := r[jj] + dx;
            if cur < kk then begin
                tt := 0;
                cur := kk;
                ii := jj;
            end;
        end; 
        ct[i] := ct[ii];
        if tt > 0 then dec(ct[i][tt][1], ct[i][tt][2]);
        r[i] := cur;
    end;
                ans := 0;
                for i := 1 to n do
                        ans := max(ans, r[i]);
                write(ans);
end.
